package com.hxd.otc.utils;

import com.hxd.otc.module.wallet.bean.WalletAccountInfoBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 包  名 :  com.hxd.otc.utils
 * 类  名 :  WalletCoinTypes
 * 作  者 :  zjl
 * 时  间 :  2018/8/27 17:57
 * 描  述 :  ${TODO}
 */
public class WalletCoinTypes {

    private static WalletCoinTypes mInstance;

    public List<WalletAccountInfoBean.HoldCoinDetailVo> holdCoinDetailVos;

    Map<String, WalletAccountInfoBean.HoldCoinDetailVo> holdCoinDetailVoMap = new HashMap<>();

    private WalletCoinTypes() {
    }

    public static WalletCoinTypes getInstance() {
        synchronized (WalletCoinTypes.class) {
            if (mInstance == null) {
                mInstance = new WalletCoinTypes();
            }
        }
        return mInstance;
    }

    public Map<String, WalletAccountInfoBean.HoldCoinDetailVo> getCoinTypes() {
        return holdCoinDetailVoMap;

    }

    public String getAddress(String key) {

        if (holdCoinDetailVoMap == null) {
            return null;
        }
        if (!holdCoinDetailVoMap.containsKey(key)) {
            return "";
        }
        if (holdCoinDetailVoMap.get(key) == null){
            return "";
        }
        return holdCoinDetailVoMap.get(key).address;
    }

    public double getBalance(String key) {
        if (holdCoinDetailVoMap == null) {
            return 0.0;
        }
        if (!holdCoinDetailVoMap.containsKey(key)) {
            return 0.0;
        }
        if (holdCoinDetailVoMap.get(key) == null) {
            return 0.0;
        }
        return holdCoinDetailVoMap.get(key).balance;
    }

    public void saveAccountInfo(List<WalletAccountInfoBean.HoldCoinDetailVo> beans) {
        if (beans == null && beans.size() == 0) {
            return;
        }
        holdCoinDetailVos = beans;
        for (int i = 0; i < holdCoinDetailVos.size(); i++) {
            holdCoinDetailVoMap.put(holdCoinDetailVos.get(i).coinType, holdCoinDetailVos.get(i));
        }

    }
}
